package com.capgemini.simpleappblanche.utils;

import org.springframework.util.StringUtils;

public class ValidatorTools {

    /**
     * REGEX to check the numeric number address
     */
    private static final String REGEX_NUMERIC = "\\d+";
    
    /**
     * REGEX to check the email address
     */
    private static final String REGEX_EMAIL_ADDRESS = "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,})$";
    
    /**
     * REGEX to check phone number
     */
    private static final String REGEX_PHONE_NUMBER = "(\\([\\+]?[0-9]{1,3}\\))?[0-9\\ -\\./]{6,50}";
    
	/**
	 * test if numeric
	 * @param value value to test
	 * @return true if numeric, false in other case
	 */
	public static boolean isNumeric(final String value){
		if(!StringUtils.hasText(value)){
			return false;
		}
		return value.matches(REGEX_NUMERIC);
	}
	
	/**
	 * test if email
	 * @param value value to test
	 * @return true if email, false in other case
	 */
	public static boolean isEmail(final String value){
		if(!StringUtils.hasText(value)){
			return false;
		}
		return value.matches(REGEX_EMAIL_ADDRESS);
	}
	
	/**
	 * test if phone
	 * @param value value to test
	 * @return true if phone, false in other case
	 */
	public static boolean isPhone(final String value){
		if(!StringUtils.hasText(value)){
			return false;
		}
		return value.matches(REGEX_PHONE_NUMBER);
	}
}
